﻿using System;
using Autofac;

namespace Inovout.Component
{
    public class ComponentResolver : IComponentResolver, IDisposable
    {
        private readonly ILifetimeScope innerContainer;

        internal ComponentResolver(ILifetimeScope container)
        {
            innerContainer = container;
        }
        public bool IsRegistered<TService>()
        {
            return innerContainer.IsRegistered<TService>();
        }
        public bool IsRegistered(Type serviceType)
        {
            return innerContainer.IsRegistered(serviceType);
        }
        public object Resolve(Type serviceType)
        {
            return innerContainer.Resolve(serviceType);
        }
        public TService Resolve<TService>(Type serviceType)
        {
            return (TService)Resolve(serviceType);
        }

        public TService Resolve<TService>()
        {
            return innerContainer.Resolve<TService>();
        }

        public void Dispose()
        {
            innerContainer.Dispose();
        }

        public IComponentResolver BeginLifetimeScope()
        {
            return new ComponentResolver(innerContainer.BeginLifetimeScope());
        }
    }
}
